// ==============================================================================================
// OfficeMenu.cs
//
// Created by: NI, 2007.03.27
// Revised by: NI, 2007.11.23
// ==============================================================================================
using RibbonExplorer.Storage;
using System.Linq;

namespace RibbonExplorer.Entities
{
  // ==============================================================================================
  /// <summary>
  /// This class represents the controls on the Office menu.
  /// </summary>
  // ==============================================================================================
  public sealed class OfficeMenu : SpecialGroup
  {
    #region Lifecycle methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates an instance of this Office menu.
    /// </summary>
    /// <param name="ribbon">Parent ribbon.</param>
    // --------------------------------------------------------------------------------------------
    public OfficeMenu(Ribbon ribbon)
      : base("Office Menu", ribbon)
    {
    }

    #endregion

    #region Overidden methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Loads the controls belonging to this group.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    protected override void OnLoadChildren()
    {
      // --- Try to obtain the ribbon table
      RibbonTable ribbonTable;
      if (RibbonTableCache.TryGetValue(ParentRibbon.Id, out ribbonTable))
      {
        var controls = from control in ribbonTable.ControlList
                       where control.Tab == "Office Menu" &&
                             control.Group == ""
                       orderby control.Ordering
                       select control;

        foreach (RibbonTableItem item in controls)
        {
          RibbonControl newControl = new RibbonControl(item.ControlId, item, this);
          if (!Controls.ContainsKey(item.ControlId))
          {
            Controls.Add(item.ControlId, newControl);
          }
        }
      }
    }

    #endregion
  }
}